package com.alibaba.day0318yk.Exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:项目中增加统一异常处理
 * @author: Wang
 * @create: 2024-03-18 12:52
 **/
//@ControllerAdvice
public class GlobalException {

    @ExceptionHandler
    @ResponseBody
    private Map<String,Object> Exception(Exception exception){
        HashMap<String, Object> map = new HashMap<>();
        String message = exception.getMessage();
        MalformedParameterizedTypeException malformedParameterizedTypeException = (MalformedParameterizedTypeException) exception;
        map.put("status",false);
        if (exception == malformedParameterizedTypeException ){
            map.put("msg","错误");
        }
        map.put("msg","系统异常");
        return map;
    }

}
